<?php
namespace Common\ORG\Qy;

/**
 * 应用栏目管理
 * 
*/

use \Common\ORG\Tools\Http;

class App extends Base{
    const URL_QUERY =  'https://qyapi.weixin.qq.com/cgi-bin/agent/list';
    const URL_GET = 'https://qyapi.weixin.qq.com/cgi-bin/agent/get';
    const URL_SET = 'https://qyapi.weixin.qq.com/cgi-bin/agent/set';

    //初始化函数
    public function __construct($token)
    {
        $this->_token = $token;
    }

    /**
     * 查询企业号应用列表
     * 
    */
    public function query()
    {
        $ret = $this->m_ret;
        $url = self::URL_QUERY.'?access_token='.urlencode($this->_token);
        $str = http::get($url);
        $crackData = $this->crackRes( $str );
        $ret['rcode'] = $crackData['rcode'];
        if ($ret['rcode'])
            $ret['data'] = $crackData['data']['agentlist'];
        $ret['msg'] = $ret['rcod'] ? 'OK':$crackData['msg'];
        return $ret;
    }

    public function set()
    {
        //
    }

    public function get( $id )
    {
        $ret = $this->m_ret;
        $data = array();
        $data['access_token'] = urlencode( $this->_token);
        $data['agentid'] = $id;
        $url = self::URL_GET.'?'.http_build_query($data);
        $str = http::get($url);
        $crackData = $this->crackRes( $str );
        $ret['rcode'] = $crackData['rcode'];
        if ($ret['rcode'])
            $ret['data'] = $crackData['data'];
        $ret['msg'] = $ret['rcod'] ? 'OK':$crackData['msg'];
        return $ret;
    }
}

?>